Page({
  data: {
    publishPermissions: [] as any,
    isEditor: false,
    selected: 0,
    id: 0,
  },
  onLoad() {
    const pages = getCurrentPages()
    const { publishPermissions, isEditor, selected, id } = pages[pages.length - 2].data
    this.setData({
      publishPermissions,
      isEditor,
      selected,
      id,
    })
  },
  /** 选择发言权限 */
  selectRules(e: WechatMiniprogram.CustomEvent) {
    const {
      currentTarget: {
        dataset: { index },
      },
    } = e
    const {
      data: { publishPermissions },
    } = this
    const pages = getCurrentPages()
    const lastpage = pages[pages.length - 2]
    lastpage.setData({
      selected: index,
      form: { ...lastpage.data.form, publish_permission: publishPermissions[index].value },
    })
    wx.navigateBack({
      delta: 1,
    })
  },
  /** 跳转指定用户发言页面 */
  toMember() {
    wx.navigateTo({
      url: `/mine/create-topic/publishRules/member/member?id=${this.data.id}`,
    })
  },
})
